﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace isDrone
{
    public partial class TelemetryForm : Form
    {
        public TelemetryForm(ISDrone drone)
        {
            InitializeComponent();
            _drone = drone;
        }
    ISDrone _drone;
        private Telemetry _telemetry;

        private void открытьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                _telemetry = new Telemetry(_drone);
                _telemetry.Load(openFileDialog1.FileName);
                Show2D();
            }

        }

        public void Show2D()
        {
            List<double[]> point = new List<double[]>();
            chart1.Series[0].Points.Clear();
            point.Add(new double[] {0, 0, 0});
            double angle = _telemetry.Navigation[0].Yaw;
            for (int i = 1; i < _telemetry.Navigation.Count; i++)
            {
                var t = new double[3];
                var dt=
               _telemetry.Time(_telemetry.Navigation[i].Time) -
                        _telemetry.Time(_telemetry.Navigation[i - 1].Time);

                t[0] = point[point.Count - 1][0] + dt;
                        
                t[1] =(
                    point[point.Count - 1][1] + _telemetry.Navigation[i].Velocity.X * dt) * Math.Sin(_telemetry.Navigation[i].Yaw-angle);
                t[2] =(
                   point[point.Count - 1][2] + _telemetry.Navigation[i].Velocity.Y * dt) * Math.Cos(_telemetry.Navigation[i].Yaw - angle);
                point.Add(t);
            }
            foreach (var t in point)
                chart1.Series[0].Points.AddXY(t[1], t[2]);
        }
    }
}
